package com.mine.hrx.controllers;

import com.mine.hrx.model.Employee;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @功能
 * @创建时间 2020/4/15
 */
@RestController
@RequestMapping("hrx")
//@DefaultProperties(defaultFallback = "orderFallBack")
public class HxController {
    @Autowired
    private RestTemplate restTemplate;
    //下订单
     @GetMapping("/{id}")
     @HystrixCommand(fallbackMethod = "orderFallBack")
     public Employee findProduct(@PathVariable Integer id) {
         return restTemplate.getForObject("http://ability-service/ablivity/1", Employee.class);
     }
    //降级方法
     public Employee orderFallBack() {
         Employee product = new Employee();
         product.setId(-1);
         product.setAddress("熔断:触发降级方法");
         return product;    }
}
